<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>管理员控制台 - 币胜客pro</title>
  <link rel="stylesheet" href="styles.css">
  <link rel="stylesheet" href="trading-modal.css">
  <style>
    /* 管理员页面专用样式 */
    .admin-container {
      max-width: 1200px;
      margin: 0 auto;
      padding: 20px;
    }
    
    .admin-header {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;
      padding: 20px;
      border-radius: 12px;
      margin-bottom: 30px;
      box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    }
    
    .admin-title {
      font-size: 28px;
      font-weight: 700;
      margin: 0 0 8px 0;
    }
    
    .admin-subtitle {
      font-size: 16px;
      opacity: 0.9;
      margin: 0;
    }
    
    .admin-stats {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
      gap: 20px;
      margin-bottom: 30px;
    }
    
    .stat-card {
      background: white;
      padding: 24px;
      border-radius: 12px;
      box-shadow: 0 2px 12px rgba(0,0,0,0.08);
      border: 1px solid rgba(0,0,0,0.05);
    }
    
    .stat-value {
      font-size: 32px;
      font-weight: 700;
      color: #1f2937;
      margin: 0 0 8px 0;
    }
    
    .stat-label {
      font-size: 14px;
      color: #6b7280;
      margin: 0;
    }
    
    .admin-sections {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
      gap: 30px;
    }
    
    .admin-section {
      background: white;
      border-radius: 12px;
      box-shadow: 0 2px 12px rgba(0,0,0,0.08);
      border: 1px solid rgba(0,0,0,0.05);
      overflow: hidden;
    }
    
    .section-header {
      background: #f8fafc;
      padding: 20px;
      border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .section-title {
      font-size: 18px;
      font-weight: 600;
      color: #1f2937;
      margin: 0 0 4px 0;
    }
    
    .section-subtitle {
      font-size: 14px;
      color: #6b7280;
      margin: 0;
    }
    
    .section-content {
      padding: 20px;
    }
    
    .user-list {
      max-height: 400px;
      overflow-y: auto;
    }
    
    .user-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 0;
      border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .user-item:last-child {
      border-bottom: none;
    }
    
    .user-info {
      flex: 1;
    }
    
    .user-email {
      font-weight: 500;
      color: #1f2937;
      margin: 0 0 4px 0;
    }
    
    .user-meta {
      font-size: 12px;
      color: #6b7280;
      margin: 0;
    }
    
    .user-actions {
      display: flex;
      gap: 8px;
    }
    
    .btn-admin {
      padding: 6px 12px;
      border: none;
      border-radius: 6px;
      font-size: 12px;
      cursor: pointer;
      transition: all 0.2s ease;
    }
    
    .btn-admin.primary {
      background: #3b82f6;
      color: white;
    }
    
    .btn-admin.primary:hover {
      background: #2563eb;
    }
    
    .btn-admin.danger {
      background: #ef4444;
      color: white;
    }
    
    .btn-admin.danger:hover {
      background: #dc2626;
    }
    
    .btn-admin.secondary {
      background: #6b7280;
      color: white;
    }
    
    .btn-admin.secondary:hover {
      background: #4b5563;
    }
    
    .system-logs {
      max-height: 300px;
      overflow-y: auto;
      background: #1f2937;
      color: #f9fafb;
      padding: 16px;
      border-radius: 8px;
      font-family: 'Courier New', monospace;
      font-size: 12px;
      line-height: 1.4;
    }
    
    .log-entry {
      margin-bottom: 8px;
      padding: 4px 0;
    }
    
    .log-time {
      color: #9ca3af;
    }
    
    .log-level {
      font-weight: bold;
    }
    
    .log-level.info { color: #3b82f6; }
    .log-level.warn { color: #f59e0b; }
    .log-level.error { color: #ef4444; }
    
    .refresh-btn {
      background: #10b981;
      color: white;
      border: none;
      padding: 8px 16px;
      border-radius: 6px;
      cursor: pointer;
      font-size: 14px;
      transition: all 0.2s ease;
    }
    
    .refresh-btn:hover {
      background: #059669;
    }
    
    .loading {
      text-align: center;
      padding: 20px;
      color: #6b7280;
    }
    
    .error {
      text-align: center;
      padding: 20px;
      color: #ef4444;
    }
    
    /* 订单历史样式 */
    .order-history-item {
      background: white;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: 8px;
      padding: 16px;
      margin-bottom: 12px;
      box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .order-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
      padding-bottom: 8px;
      border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .order-symbol {
      font-weight: 600;
      font-size: 16px;
      color: #1f2937;
    }
    
    .order-side {
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: 500;
    }
    
    .order-side.buy {
      background: #dcfce7;
      color: #166534;
    }
    
    .order-side.sell {
      background: #fee2e2;
      color: #991b1b;
    }
    
    .order-status {
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: 500;
    }
    
    .order-status.success {
      background: #dcfce7;
      color: #166534;
    }
    
    .order-status.warning {
      background: #fef3c7;
      color: #92400e;
    }
    
    .order-status.error {
      background: #fee2e2;
      color: #991b1b;
    }
    
    .order-status.info {
      background: #dbeafe;
      color: #1e40af;
    }
    
    .order-details {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 16px;
    }
    
    .order-info, .order-meta, .order-times {
      display: flex;
      flex-direction: column;
      gap: 4px;
    }
    
    .order-info span, .order-meta span, .order-times span {
      font-size: 12px;
      color: #6b7280;
    }
    
    /* 策略管理样式 */
    .strategy-item {
      background: white;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: 8px;
      padding: 16px;
      margin-bottom: 12px;
      box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .strategy-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;
      padding-bottom: 8px;
      border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .strategy-title {
      font-weight: 600;
      font-size: 16px;
      color: #1f2937;
    }
    
    .strategy-body {
      display: none;
      margin-top: 12px;
    }
    
    .strategy-body.expanded {
      display: block;
    }
    
    .strategy-field {
      margin-bottom: 8px;
    }
    
    .strategy-field label {
      display: block;
      font-weight: 500;
      color: #374151;
      margin-bottom: 4px;
    }
    
    .strategy-field input {
      width: 100%;
      padding: 6px 8px;
      border: 1px solid #d1d5db;
      border-radius: 4px;
      font-size: 14px;
    }
    
    .strategy-status-switch {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    
    .strategy-status-switch input[type="checkbox"] {
      width: auto;
      margin: 0;
    }
    
    .strategy-actions {
      display: flex;
      gap: 8px;
      margin-top: 12px;
      justify-content: flex-end;
    }
    
    .strategy-actions .btn {
      padding: 6px 12px;
      font-size: 12px;
    }
    
    .strategy-reveal-box {
      margin-top: 12px;
      padding: 12px;
      background: #f9fafb;
      border-radius: 6px;
      border: 1px solid #e5e7eb;
    }
    
    .strategy-reveal-box h4 {
      margin: 0 0 8px 0;
      color: #1f2937;
    }
    
    .strategy-reveal-field {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 8px;
    }
    
    .strategy-reveal-field input,
    .strategy-reveal-field textarea {
      flex: 1;
      padding: 6px 8px;
      border: 1px solid #d1d5db;
      border-radius: 4px;
      font-size: 12px;
    }
    
    .strategy-reveal-field textarea {
      min-height: 60px;
      resize: vertical;
    }
    
    .strategy-reveal-field .btn {
      padding: 4px 8px;
      font-size: 11px;
    }
    
    .strategy-filter-bar {
      display: flex;
      gap: 8px;
      margin: 8px 0;
      flex-wrap: wrap;
    }
    
    .strategy-filter-bar input,
    .strategy-filter-bar select {
      padding: 6px 8px;
      border: 1px solid #d1d5db;
      border-radius: 4px;
      font-size: 12px;
    }
    
    .strategy-pager-bar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 12px;
      padding-top: 8px;
      border-top: 1px solid rgba(0,0,0,0.05);
    }
    
    .strategy-pager-info {
      font-size: 12px;
      color: #6b7280;
    }
    
    .strategy-pager-controls {
      display: flex;
      gap: 8px;
    }
    
    .strategy-pager-controls .btn {
      padding: 4px 8px;
      font-size: 12px;
    }
    
    @media (max-width: 768px) {
      .admin-container {
        padding: 10px;
      }
      
      .admin-sections {
        grid-template-columns: 1fr;
      }
      
      .admin-stats {
        grid-template-columns: 1fr;
      }
      
      .order-details {
        grid-template-columns: 1fr;
        gap: 8px;
      }
    }
  </style>
</head>
<body>
  <div class="admin-container">
    <!-- 管理员头部 -->
    <div class="admin-header">
      <div style="display: flex; justify-content: space-between; align-items: center;">
        <div>
          <h1 class="admin-title" onclick="openAdminDashboard()" style="cursor: pointer; transition: all 0.3s ease;">🔧 管理员控制台</h1>
          <p class="admin-subtitle">系统监控 · 用户管理 · 数据分析</p>
        </div>
        <div style="display: flex; gap: 12px;">
          <button class="refresh-btn" onclick="window.location.href='broadcast-manager.html'" style="background: #3b82f6;">📡 广播管理</button>
          <button class="refresh-btn" onclick="window.location.href='strategy-manager.html'" style="background: #f59e0b;">⚙️ 策略管理</button>
          <a class="refresh-btn" href="order-history.html" style="background: #8b5cf6;display:inline-flex;align-items:center;justify-content:center;text-decoration:none;">📋 订单历史</a>
          <button class="refresh-btn" onclick="goToUserPage()" style="background: #6b7280;">👤 返回用户页面</button>
        </div>
      </div>
    </div>
    
    <!-- 统计卡片 -->
    <div class="admin-stats">
      <div class="stat-card">
        <div class="stat-value" id="total-users">-</div>
        <div class="stat-label">总用户数</div>
      </div>
      <div class="stat-card">
        <div class="stat-value" id="active-users">-</div>
        <div class="stat-label">活跃用户</div>
      </div>
      <div class="stat-card">
        <div class="stat-value" id="total-connectors">-</div>
        <div class="stat-label">连接器总数</div>
      </div>
      <div class="stat-card">
        <div class="stat-value" id="system-status">-</div>
        <div class="stat-label">系统状态</div>
      </div>
    </div>
    
    <!-- 管理员功能区域 -->
    <div class="admin-sections">
      <!-- 用户管理 -->
      <div class="admin-section">
        <div class="section-header">
          <h2 class="section-title">👥 用户管理</h2>
          <p class="section-subtitle">管理系统用户和权限</p>
        </div>
        <div class="section-content">
          <div class="user-list" id="user-list">
            <div class="loading">加载中...</div>
          </div>
        </div>
      </div>
      
      <!-- 系统监控 -->
      <div class="admin-section">
        <div class="section-header">
          <h2 class="section-title">📊 系统监控</h2>
          <p class="section-subtitle">实时系统状态和性能指标</p>
        </div>
        <div class="section-content">
          <button class="refresh-btn" onclick="refreshSystemStatus()">🔄 刷新状态</button>
          <div id="system-metrics" style="margin-top: 16px;">
            <div class="loading">加载中...</div>
          </div>
        </div>
      </div>
      
      <!-- 系统日志 -->
      <div class="admin-section">
        <div class="section-header">
          <h2 class="section-title">📝 系统日志</h2>
          <p class="section-subtitle">实时系统日志和错误信息</p>
        </div>
        <div class="section-content">
          <button class="refresh-btn" onclick="refreshLogs()">🔄 刷新日志</button>
          <div class="system-logs" id="system-logs">
            <div class="log-entry">
              <span class="log-time">[2024-01-01 12:00:00]</span>
              <span class="log-level info">[INFO]</span>
              系统启动完成
            </div>
          </div>
        </div>
      </div>
      
      <!-- 数据统计 -->
      <div class="admin-section">
        <div class="section-header">
          <h2 class="section-title">📈 数据统计</h2>
          <p class="section-subtitle">用户数据和交易统计</p>
        </div>
        <div class="section-content">
          <button class="refresh-btn" onclick="refreshDataStats()">🔄 刷新数据</button>
          <div id="data-stats" style="margin-top: 16px;">
            <div class="loading">加载中...</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  
  
  <!-- 广播管理弹窗 -->
  <div class="modal" id="broadcast-manager-modal" style="display: none;">
    <div class="modal-backdrop" onclick="closeBroadcastManager()"></div>
    <div class="modal-content" style="max-width: 1200px; max-height: 90vh; overflow-y: auto;">
      <div class="modal-header">
        <div class="modal-icon">📡</div>
        <div>
          <h2 class="modal-title">广播分组管理</h2>
          <p class="modal-subtitle">管理广播分组、成员和风控配置</p>
          <div id="data-source-indicator" class="data-source-indicator" style="display: none;">
            <span class="indicator-dot"></span>
            <span class="indicator-text">使用模拟数据演示</span>
          </div>
        </div>
        <button class="modal-close" onclick="closeBroadcastManager()">&times;</button>
      </div>
      
      <div class="modal-body">
        <!-- 广播分组列表 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📋</span>
            <h3>广播分组列表</h3>
            <button class="btn primary" onclick="openCreateGroupModal()">+ 创建分组</button>
          </div>
          <div id="broadcast-groups-list">
            <p class="muted">加载中...</p>
          </div>
        </div>
        
        <!-- 风控配置 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">⚙️</span>
            <h3>风控配置</h3>
            <button class="btn secondary" onclick="loadRiskConfig()">刷新配置</button>
          </div>
          <div id="risk-config-content">
            <p class="muted">加载中...</p>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <!-- 创建分组弹窗 -->
  <div class="modal" id="create-group-modal" style="display: none;">
    <div class="modal-backdrop" onclick="closeCreateGroupModal()"></div>
    <div class="modal-content">
      <div class="modal-header">
        <div class="modal-icon">➕</div>
        <div>
          <h2 class="modal-title">创建广播分组</h2>
          <p class="modal-subtitle">创建新的广播分组</p>
        </div>
        <button class="modal-close" onclick="closeCreateGroupModal()">&times;</button>
      </div>
      
      <div class="modal-body">
        <div class="form-group">
          <label class="form-label">分组名称</label>
          <input type="text" id="group-name" class="form-input" placeholder="请输入分组名称" />
        </div>
        <div class="form-group">
          <label class="form-label">分组描述</label>
          <textarea id="group-description" class="form-input" rows="3" placeholder="请输入分组描述"></textarea>
        </div>
        <div class="form-group">
          <label class="form-label">分组类型</label>
          <select id="group-type" class="form-select">
            <option value="public">公开分组</option>
            <option value="private">私有分组</option>
            <option value="vip">VIP分组</option>
          </select>
        </div>
        <div class="form-actions">
          <button class="btn primary" onclick="createBroadcastGroup()">创建分组</button>
          <button class="btn secondary" onclick="closeCreateGroupModal()">取消</button>
        </div>
      </div>
    </div>
  </div>
  
  <!-- 分组详情弹窗 -->
  <div class="modal" id="group-detail-modal" style="display: none;">
    <div class="modal-backdrop" onclick="closeGroupDetailModal()"></div>
    <div class="modal-content" style="max-width: 1000px;">
      <div class="modal-header">
        <div class="modal-icon">👥</div>
        <div>
          <h2 class="modal-title" id="group-detail-title">分组详情</h2>
          <p class="modal-subtitle" id="group-detail-subtitle">管理分组成员</p>
        </div>
        <button class="modal-close" onclick="closeGroupDetailModal()">&times;</button>
      </div>
      
      <div class="modal-body">
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">👥</span>
            <h3>分组成员</h3>
            <button class="btn primary" onclick="openAddMemberModal()">+ 添加成员</button>
          </div>
          <div id="group-members-list">
            <p class="muted">加载中...</p>
          </div>
        </div>
        
        <div class="form-actions">
          <button class="btn danger" onclick="deleteCurrentGroup()">删除分组</button>
          <button class="btn secondary" onclick="closeGroupDetailModal()">关闭</button>
        </div>
      </div>
    </div>
  </div>
  
  <!-- 策略管理弹窗 -->
  <div class="modal" id="strategy-manager-modal" style="display: none;">
    <div class="modal-backdrop" onclick="closeStrategyManager()"></div>
    <div class="modal-content" style="max-width: 1200px; max-height: 90vh; overflow-y: auto;">
      <div class="modal-header">
        <div class="modal-icon">⚙️</div>
        <div>
          <h2 class="modal-title">策略管理</h2>
          <p class="modal-subtitle">管理系统策略、创建新策略和查看策略详情</p>
        </div>
        <button class="modal-close" onclick="closeStrategyManager()">&times;</button>
      </div>
      
      <div class="modal-body">
        <!-- 策略统计 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📊</span>
            <h3>策略统计</h3>
            <button class="btn secondary" onclick="loadStrategyStats()">🔄 刷新统计</button>
          </div>
          <div id="strategy-stats-content">
            <p class="muted">加载中...</p>
          </div>
        </div>
        
        <!-- 策略列表 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📋</span>
            <h3>策略列表</h3>
            <div style="display: flex; gap: 8px;">
              <button class="btn secondary" onclick="loadStrategyList()">🔄 刷新列表</button>
              <button class="btn primary" onclick="openCreateStrategyModal()">+ 创建策略</button>
            </div>
          </div>
          
          <!-- 筛选栏 -->
          <div id="strategy-filter-bar" style="display: none; margin: 8px 0; gap: 8px; flex-wrap: wrap;"></div>
          
          <!-- 策略列表内容 -->
          <div id="strategy-list-content">
            <p class="muted">加载中...</p>
          </div>
          
          <!-- 分页 -->
          <div id="strategy-pager-bar" style="display: flex; justify-content: space-between; align-items: center; margin-top: 8px;"></div>
        </div>
      </div>
    </div>
  </div>
  
  <!-- 管理员概览页面 -->
  <div class="modal" id="admin-dashboard-modal" style="display: none;">
    <div class="modal-backdrop" onclick="closeAdminDashboard()"></div>
    <div class="modal-content" style="max-width: 1400px; max-height: 90vh; overflow-y: auto;">
      <div class="modal-header">
        <div class="modal-icon">🏠</div>
        <div>
          <h2 class="modal-title">管理员概览</h2>
          <p class="modal-subtitle">系统监控 · 用户管理 · 数据分析</p>
        </div>
        <button class="modal-close" onclick="closeAdminDashboard()">&times;</button>
      </div>
      
      <div class="modal-body">
        <!-- 系统概览统计 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📊</span>
            <h3>系统概览</h3>
            <button class="btn secondary" onclick="refreshSystemStats()">🔄 刷新统计</button>
          </div>
          <div id="system-overview-content">
            <div class="loading">加载中...</div>
          </div>
        </div>
        
        <!-- 快速操作 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">⚡</span>
            <h3>快速操作</h3>
          </div>
            <div class="quick-actions-grid">
              <div class="quick-action-card" onclick="openBroadcastManager()">
              <div class="quick-action-icon">📡</div>
              <div class="quick-action-title">广播管理</div>
              <div class="quick-action-desc">管理广播订单</div>
            </div>
            <div class="quick-action-card" onclick="openStrategyManager()">
              <div class="quick-action-icon">⚙️</div>
              <div class="quick-action-title">策略管理</div>
              <div class="quick-action-desc">管理交易策略</div>
            </div>
              <div class="quick-action-card" onclick="window.location.href='order-history.html'">
                <div class="quick-action-icon">📋</div>
                <div class="quick-action-title">订单历史</div>
              <div class="quick-action-desc">查看订单记录</div>
            </div>
            <div class="quick-action-card" onclick="openUserManagement()">
              <div class="quick-action-icon">👥</div>
              <div class="quick-action-title">用户管理</div>
              <div class="quick-action-desc">管理系统用户</div>
            </div>
          </div>
        </div>
        
        <!-- 系统监控 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📈</span>
            <h3>系统监控</h3>
            <button class="btn secondary" onclick="refreshSystemMonitoring()">🔄 刷新监控</button>
          </div>
          <div id="system-monitoring-content">
            <div class="loading">加载中...</div>
          </div>
        </div>
        
        <!-- 数据分析 -->
        <div class="trading-section">
          <div class="section-header">
            <span class="section-icon">📊</span>
            <h3>数据分析</h3>
            <button class="btn secondary" onclick="refreshDataAnalysis()">🔄 刷新数据</button>
          </div>
          <div id="data-analysis-content">
            <div class="loading">加载中...</div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- 创建/编辑策略弹窗 -->
  <div class="modal" id="strategy-form-modal" style="display: none;">
    <div class="modal-backdrop" id="strategy-form-backdrop"></div>
    <div class="modal-content" id="strategy-form-content-wrapper">
      <div class="modal-header">
        <div class="modal-icon">➕</div>
        <div>
          <h2 class="modal-title" id="strategy-form-title">创建策略</h2>
          <p class="modal-subtitle" id="strategy-form-subtitle">创建新的交易策略</p>
        </div>
        <button class="modal-close" id="strategy-form-close-btn">&times;</button>
      </div>
      
      <div class="modal-body">
        <div id="strategy-form-content">
          <!-- 表单内容将在这里动态生成 -->
        </div>
      </div>
    </div>
  </div>
  
  <script src="admin.js"></script>
  <script>
    // 确保策略管理函数立即可用
    if (typeof window.openStrategyManager === 'undefined') {
      window.openStrategyManager = function() {
        console.log('Admin: 打开策略管理 (立即定义)');
        var modal = document.getElementById('strategy-manager-modal');
        if (modal) {
          modal.style.display = 'block';
          // 延迟调用其他函数，确保它们已加载
          setTimeout(function() {
            if (typeof window.loadStrategyStats === 'function') {
              window.loadStrategyStats();
            }
            if (typeof window.loadStrategyList === 'function') {
              window.loadStrategyList();
            }
            if (typeof window.buildStrategyFilterBar === 'function') {
              window.buildStrategyFilterBar();
            }
          }, 100);
        } else {
          alert('策略管理弹窗未找到');
        }
      };
      
      window.closeStrategyManager = function() {
        console.log('Admin: 关闭策略管理 (立即定义)');
        var modal = document.getElementById('strategy-manager-modal');
        if (modal) {
          modal.style.display = 'none';
        }
      };
    }
  </script>
  <script>
    // 测试函数是否在全局作用域中
    console.log('测试函数是否存在:', typeof toggleAccountDropdown);
    if (typeof toggleAccountDropdown === 'undefined') {
      console.error('toggleAccountDropdown 函数未定义！');
    } else {
      console.log('toggleAccountDropdown 函数已定义');
    }
    
    // 测试广播管理相关函数
    console.log('测试广播管理函数:');
    console.log('- request:', typeof window.request);
    console.log('- loadBroadcastGroups:', typeof window.loadBroadcastGroups);
    console.log('- createBroadcastGroup:', typeof window.createBroadcastGroup);
    console.log('- loadRiskConfig:', typeof window.loadRiskConfig);
    console.log('- openBroadcastManager:', typeof window.openBroadcastManager);
    
    // 测试交易中心相关函数 (已删除一键下单功能)
    // console.log('测试交易中心函数:');
    // console.log('- openTradingCenter:', typeof window.openTradingCenter);
    // console.log('- initTradingCenter:', typeof window.initTradingCenter);
    // console.log('- collectOrderData:', typeof window.collectOrderData);
    // console.log('- executeOrder:', typeof window.executeOrder);
    
    // 测试订单历史相关函数
    console.log('测试订单历史函数:');
    console.log('- openOrderHistory:', typeof window.openOrderHistory);
    console.log('- loadOrderHistory:', typeof window.loadOrderHistory);
    
    // 测试策略管理相关函数
    console.log('测试策略管理函数:');
    console.log('- openStrategyManager:', typeof window.openStrategyManager);
    console.log('- closeStrategyManager:', typeof window.closeStrategyManager);
    console.log('- loadStrategyStats:', typeof window.loadStrategyStats);
    console.log('- loadStrategyList:', typeof window.loadStrategyList);
    console.log('- openCreateStrategyModal:', typeof window.openCreateStrategyModal);
    console.log('- closeStrategyForm:', typeof window.closeStrategyForm);
    console.log('- saveStrategy:', typeof window.saveStrategy);
    console.log('- toggleStrategyStatus:', typeof window.toggleStrategyStatus);
    console.log('- deleteStrategy:', typeof window.deleteStrategy);
    console.log('- revealStrategySecret:', typeof window.revealStrategySecret);
    console.log('- copyToClipboard:', typeof window.copyToClipboard);
    
    // 如果策略管理函数未定义，提供备用定义
    if (typeof window.openStrategyManager === 'undefined') {
      console.warn('策略管理函数未定义，正在设置备用定义...');
      
      window.openStrategyManager = function() {
        console.log('Admin: 打开策略管理 (备用定义)');
        var modal = document.getElementById('strategy-manager-modal');
        if (modal) {
          modal.style.display = 'block';
          // 尝试调用其他函数
          if (typeof window.loadStrategyStats === 'function') {
            window.loadStrategyStats();
          }
          if (typeof window.loadStrategyList === 'function') {
            window.loadStrategyList();
          }
        } else {
          alert('策略管理弹窗未找到，请检查页面结构');
        }
      };
      
      window.closeStrategyManager = function() {
        console.log('Admin: 关闭策略管理 (备用定义)');
        var modal = document.getElementById('strategy-manager-modal');
        if (modal) {
          modal.style.display = 'none';
        }
      };
      
      console.log('已设置策略管理备用函数');
    }
    
    // 确保创建策略函数立即可用
    if (typeof window.openCreateStrategyModal === 'undefined') {
      console.warn('创建策略函数未定义，正在设置备用定义...');
      
      window.openCreateStrategyModal = function() {
        console.log('Admin: 打开创建策略表单 (备用定义)');
        var modal = document.getElementById('strategy-form-modal');
        if (modal) {
          modal.style.display = 'block';
        } else {
          alert('创建策略弹窗未找到');
        }
      };
      
      console.log('已设置创建策略备用函数');
    }
    
    // 添加调试功能
    window.debugStrategyFunctions = function() {
      console.log('=== 策略管理函数调试 ===');
      console.log('openStrategyManager:', typeof window.openStrategyManager);
      console.log('openCreateStrategyModal:', typeof window.openCreateStrategyModal);
      console.log('toggleStrategyDetails:', typeof window.toggleStrategyDetails);
      console.log('editStrategy:', typeof window.editStrategy);
      console.log('deleteStrategy:', typeof window.deleteStrategy);
      console.log('revealStrategySecret:', typeof window.revealStrategySecret);
      console.log('toggleStrategyStatus:', typeof window.toggleStrategyStatus);
      console.log('saveStrategy:', typeof window.saveStrategy);
      console.log('closeStrategyForm:', typeof window.closeStrategyForm);
      
      // 检查DOM元素
      console.log('=== DOM元素检查 ===');
      console.log('strategy-manager-modal:', document.getElementById('strategy-manager-modal'));
      console.log('strategy-form-modal:', document.getElementById('strategy-form-modal'));
      console.log('strategy-list-content:', document.getElementById('strategy-list-content'));
      console.log('strategy-stats-content:', document.getElementById('strategy-stats-content'));
      
      // 测试展开功能
      var firstStrategy = document.querySelector('.strategy-item');
      if (firstStrategy) {
        console.log('找到第一个策略项:', firstStrategy);
        var expandBtn = firstStrategy.querySelector('button');
        if (expandBtn) {
          console.log('找到展开按钮:', expandBtn);
          console.log('按钮文本:', expandBtn.textContent);
        }
      }
    };
    
    // 自动运行调试
    setTimeout(function() {
      debugStrategyFunctions();
    }, 1000);
    
    // 添加弹窗测试功能
    window.testCreateStrategyModal = function() {
      console.log('=== 测试创建策略弹窗 ===');
      try {
        if (typeof window.openCreateStrategyModal === 'function') {
          console.log('调用 openCreateStrategyModal...');
          window.openCreateStrategyModal();
          console.log('弹窗应该已打开');
        } else {
          console.error('openCreateStrategyModal 函数未定义');
        }
      } catch (err) {
        console.error('测试创建策略弹窗失败:', err);
      }
    };
  </script>
</body>
</html>
